package cn.xydpeng.springframework.context.event;

import cn.xydpeng.springframework.context.ApplicationEvent;
import cn.xydpeng.springframework.context.ApplicationListener;
import cn.xydpeng.springframework.core.ResolvableType;
import cn.xydpeng.springframework.lang.Nullable;

import java.util.function.Predicate;

/**
 * @author xydpeng
 * @version v1.0
 * @date: 2022/10/21
 * @description:
 */
public interface ApplicationEventMulticaster {

    /**
     * Add a listener to be notified of all events.
     * @param listener the listener to add
     * @see #removeApplicationListener(ApplicationListener)
     * @see #removeApplicationListeners(Predicate)
     */
    void addApplicationListener(ApplicationListener<?> listener);

    /**
     * Remove a listener from the notification list.
     * @param listener the listener to remove
     * @see #addApplicationListener(ApplicationListener)
     * @see #removeApplicationListeners(Predicate)
     */
    void removeApplicationListener(ApplicationListener<?> listener);

    /**
     * Multicast the given application event to appropriate listeners.
     * <p>Consider using {@link #multicastEvent(ApplicationEvent, ResolvableType)}
     * if possible as it provides better support for generics-based events.
     * @param event the event to multicast
     */
    void multicastEvent(ApplicationEvent event);

    void multicastEvent(ApplicationEvent event, @Nullable ResolvableType eventType);


}
